/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package services;

import beans.FollowBean;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PUT;
import javax.ws.rs.core.MediaType;
import org.json.JSONObject;

/**
 * REST Web Service
 *
 * @author tae
 */
@Path("resource/FollowFriend")
@Stateless
public class FollowFriendResource {

    @Context
    private UriInfo context;
    
    @EJB
    private FollowBean followBean;

    /**
     * Creates a new instance of FollowFriendResource
     */
    public FollowFriendResource() {
    }

    
    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.TEXT_PLAIN)
    public String execute(String request)
    {
        JSONObject json = new JSONObject(request);
        
        long senderID = json.getLong("senderID");
        long followID = json.getLong("followID");
        
        boolean result = followBean.followFriend(senderID, followID);
        
        if(result)
        {
            return "SUCCESS";
        }
        else
        {
            return "FAIL";
        }
    }
}
